package com.yg.item.controller;


import com.yg.item.feign.ImageFeignService;
import com.yg.item.pojo.Item;
import com.yg.item.pojo.vo.HotItemVo;
import com.yg.item.pojo.vo.ItemVo;
import com.yg.item.service.ItemService;
import com.yg.util.Result;
import com.yg.util.StatusCode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;
import rx.internal.operators.OnSubscribeAmb;
import springfox.documentation.annotations.ApiIgnore;

import java.util.List;

/**
 * <p>
 * 节目表 前端控制器
 * </p>
 *
 * @author 魏成龙
 * @since 2020-11-07
 */
@RestController
@RequestMapping("/item/item")
public class ItemController {

    @Autowired
    private ItemService itemService;

    //查询所有item
    @GetMapping("findAllItem")
    public Result getAllItem(){
        List<Item> list = itemService.list();

        return new Result(true, StatusCode.OK,"查询成功",list);
    }


    //根据id查询item
    @GetMapping("getById/{id}")
    public Item getItemById(@PathVariable Integer id){
        Item item = itemService.getById(id);

        return item;
    }


    //获取所有商品分类
    @GetMapping("queryAllType")
    public Result getAllCategory(){
        List<ItemVo> allCategory = itemService.getAllCategory();

        return new Result(true,StatusCode.OK,"查询成功",allCategory);

    }
    @Autowired
    private ImageFeignService imageFeignService;

    @ApiIgnore
    @GetMapping("getUrl/{id}")
    public Result getUrl(@PathVariable Long id){
        Result imageUrl = imageFeignService.getImageUrl(id);

        return imageUrl;
    }

    //查询推荐
    @GetMapping("getRecommend")
    public Result getRecommend(){
        List<HotItemVo> recommendList = itemService.getRecommendList();

        return new Result(true,StatusCode.OK,"查询成功",recommendList);
    }

    //即将开售
    @GetMapping("getOnSale")
    public Result getOnSale(){
        List<HotItemVo> onSale = itemService.getOnSale();
        return new Result(true,StatusCode.OK,"查询成功", onSale);
    }

}
